<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./libs/vue2.js"></script>
    <style>
        .parent {
            background-color: lightblue;
            padding: 10px;
        }

        .child {
            background-color: #EEE;
            padding: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <parent />
    </div>
</body>
<script>
    // 子组件
    Vue.component('child', {
        template: `
            <div class="child">
                <h1>{{title}}</h1>
            </div>
        `,
        data() {
            return {
                title: 'child子组件'
            }
        }
    });
    // 父组件
    Vue.component('parent', {
        template: `
            <div class="parent">
                <h1>{{title}}</h1>
                <button @click="handlerChild">操作子组件</button>
                <child />
            </div>
        `,
        data() {
            return {
                title: 'parent父组件'
            }
        },
        methods:{
            handlerChild(){
                // console.log(this.$children);
                this.$children[0].title='hello child!!!'
                this.$children[0].$el.style.backgroundColor='yellow';
            }
        }
    });
    new Vue({
        el: '#app'
    });
</script>

</html>